package com.ninong.ker.admin.rest;

import com.alibaba.fastjson.JSONObject;
import com.ninong.ker.common.tools.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ninong.ker.admin.sevice.FwGroupService;
import com.ninong.ker.common.annotation.perm.CmdAdmin;
import com.ninong.ker.common.response.CmdResponse;



/**
 * 组合数据表
 *
 * @author 鸠摩智
 * @email cmd
 * @date 2021-02-08 15:01:08
 */
@RestController
@RequestMapping("/cmd/v1/fwgroup")
public class FwGroupResources {

    @Autowired
    private FwGroupService fwGroupService;

    /**
     * 列表
     */
    @CmdAdmin({"admin","formdata:list"})
    @PostMapping
    public ResponseEntity<CmdResponse> list(@RequestBody JSONObject dto){
		CmdResponse response = new CmdResponse();
		response.setData(fwGroupService.listPage(dto));
		return ResponseEntity.ok(response);
    }


	@CmdAdmin({"admin","formdata:delete"})
	@DeleteMapping
	public ResponseEntity<CmdResponse> delete(@RequestBody String[] ids)  {
		fwGroupService.delete(ids);
		CmdResponse response = new CmdResponse();
		String mess = PropertyUtil.getProperty("DELETE_SUCCESS");
		response.setMessage(mess);
		return ResponseEntity.ok(response);
	}
	
	@CmdAdmin({"admin","formdata:add","formdata:update"})
	@PutMapping
	public ResponseEntity<CmdResponse> create(@RequestBody JSONObject entity) throws Exception  {
		fwGroupService.create(entity);
		return ResponseEntity.ok(new CmdResponse());
	}
	
	@CmdAdmin({"admin","formdata:detail"})
	@GetMapping("/{id}")
	public ResponseEntity<CmdResponse> get(@PathVariable String id)  {
		CmdResponse response = new CmdResponse();
		response.setData(fwGroupService.get(id));
		return ResponseEntity.ok(response);
	}

	/**
	 * 获取组合数据集合
	 * @return
	 */
	@CmdAdmin({"admin", "formdata:detail"})
	@GetMapping(value = "/treeData")
	public ResponseEntity<CmdResponse> treeData() {
		CmdResponse response = new CmdResponse();
		response.setData(fwGroupService.treeData());
		return ResponseEntity.ok(response);
	}

}
